package org.example.elasticsearch.config;

import org.example.elasticsearch.ESIndexEnum;
import org.example.elasticsearch.ESService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

/**
 * @author: sql
 * @date: 2024/6/7
 * @Description: 初始化ES索引和映射
 * @version: 1.0
 */
@Slf4j
@Component
public class ESIndexOrMappingInitialize implements CommandLineRunner {

    @Autowired
    private ESService esService;

    @Override
    public void run(String... args) throws Exception {
        ESIndexEnum[] values = ESIndexEnum.values();
        for (ESIndexEnum indexEnum : values) {
            esService.updMapping(indexEnum);
        }
        log.info("初始化ES索引和映射 执行完成");
    }
}
